public class Trans {
    public String trans (String s, int n) {
        // write code here
        boolean flg1 = false, flg2 = false;
        if (s.charAt(0) == ' ') {
            flg1 = true;
            s = s.substring(1, n);
        }
        if (s.charAt(s.length()-1) == ' ') {
            flg2 = true;
            s = s.substring(0,n-1);
        }
        char[] c = s.toCharArray();
        transfer(c);
        String[] ss = new String(c).split(" ");
        if (ss.length == 0) {
            return "  " + s;
        }
        for (int left = 0, right = ss.length-1; left < right; left++, right--) {
            swap(ss, left, right);
        }
        String ret = String.join(" ", ss);
        if (flg1) {
            ret += " ";
        }
        if (flg2) {
            ret = " " + ret;
        }
        return ret;
    }

    private void swap(String[] ss, int x, int y) {
        String tmp = ss[x];
        ss[x] = ss[y];
        ss[y] = tmp;
    }

    private void transfer(char[] c) {
        for (int i = 0; i < c.length; i++) {
            if (c[i] >= 'a' && c[i] <= 'z') {
                c[i] -= 32;
            } else if (c[i] >= 'A' && c[i] <= 'Z') {
                c[i] += 32;
            }
        }
    }

    public static void main(String[] args) {
        Trans t = new Trans();
        System.out.println(t.trans("     ", 5));
    }
}
